home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1465 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.0 KB

  1. Path: oxy.rust.net!usenet
  2. From: ebennett@rust.net
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Pointers to functions
  5. Date: Thu, 11 Jan 1996 05:15:20 GMT
  6. Organization: Rust Net - High Speed Internet in Detroit  810-642-2276
  7. Message-ID: <4d1rph$ski@oxy.rust.net>
  8. References: <4cprlp$6kl@jupiter.planet.net>
  9. NNTP-Posting-Host: liv-16.rust.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Chris Kemp <chrisk@paladn.com> wrote:
  13.  
  14. >Can I do this?
  15. >I want user to enter a function name, then the program will 
  16. >'do' the function named by the user
  17.  
  18. >char *name="home_fn";
  19. >int g;
  20. >int a=2;
  21. >int b=4;
  22.  
  23. This can be done easily under Windows, if the functions are in a DLL.
  24. The program would use GetProcAddress() to get a pointer to the
  25. fucntion specified, and then call it through that pointer.
  26.  
  27. If the functions are not in a DLL, then you would need a table of
  28. function names and addresses.  You would run through the table looking
  29. for the name entered by the user, and then call the procedure through
  30. the pointer stored in the table.
  31.  
  32. Earl Bennett
  33.  
  34.  
  35.